var app = new Vue({
	el: '#app',
	data: {
		order: [],
		customerFile:[],
		serviceFile:[],
		spare:'',
		first:true,
		openId: ''
    },
    mounted: function () {
		this.$nextTick(function () {
            var id = getUrlParam('repairRecordId');
			Server.getFromService('/getRepairRecord', {id: id}, function (result) {
				console.log(result);
				app.order = result.data.repairRecord;
				app.spare = result.data.sparepartFee.join('<br>');
				app.customerFile = result.data.customerFile;
				app.serviceFile = result.data.serviceFile;

			});
		});
	},
	updated(){
		//初始加载时初始化video控件,且工单状态在服务中,不为取消服务
		if(app.first){
			for(var i in app.customerFile){
				if(app.customerFile[i].fileType === REPAIR_FILE_TYPE_VIDEO){
					app.getFiles(app.customerFile[i].fileId);
				}
			}
			app.first = false;
		}
	},
    methods:{
    	hrefHtml: function (state,workOrderNo,productName) {
    		var id = getUrlParam('repairRecordId');
			console.log(state,REPAIR_STATE_SIGN);
    		switch (state) {
				case REPAIR_STATE_AUDIT:
				appointment(id);
				break;
				case REPAIR_STATE_BESPEAK:
				feedBack(id,workOrderNo,productName);
				break;
				case REPAIR_STATE_FEEDBACK:		
					sign(id);
				break;
    		}
    	},
        getRepairState: function(order) {

        	return {
        		state : stateToTxt(order.repairState)
        	}
        } ,
//      getOrderStep:function(state){
//			console.log(state);
//			
//          switch (state) {
//              case REPAIR_STATE_SUBMIT:
//					return '<img src="img/img27.png">';
//				case REPAIR_STATE_AUDIT:{
//					return '<img src="img/img28.png">';
//				}
//				case REPAIR_STATE_BESPEAK:
//					return '<img src="img/img28.png">';
//				case REPAIR_STATE_SIGN:
//                  return '<img src="img/img30.png">';
//              case REPAIR_STATE_CANCEL:
//                  return '';
//				default:
//					return '<img src="img/img29.png">';
//          }
//		},
		cancelRepair:function(id,workOrderNo){
			/**
			 * 取消报修服务
			 * @param {Integer} id 报修id
			 * @param {String} workOrderNo 报修工单
			 */
			mui.confirm('是否取消工单['+workOrderNo+']', function(e){
				console.log(e);
				
				if(e.index == 1){
					console.log(231);
					
					Server.postToCustomer('/cancelRepair', {id: id}, function(result){
						if(result.code === 100){
							mui.toast("取消成功!");
							app.order.repairState = REPAIR_STATE_CANCEL;
						}else{
							mui.toast('操作失败渲!');
						}
					});
				}
			});
		},
		callToServices:function(){
			console.log(2341);
			mui.confirm('是否拨打4008889880', function (e) {
				if (e.index != 0) {
					var tel = $('<a href="tel:4008889880"></a>');
					tel[0].click();
				}
			})
		},
		getRepairMethod:function(type){
			/**
			 * 判断维修方式
			 * @param {Integer} type 维修类型
			 * @return 维修名称
			 */
			if(type === REPAIR_METHOD_SCENCE){
				return "现场维修";
			}else{
				return "寄件维修";
			}
		},

		getFiles:function(fileID){
            console.log(fileID);
            
			var player = TCPlayer('f'+fileID, { // player-container-id 为播放器容器ID，必须与html中一致
                fileID: fileID, // 请传入需要播放的视频filID 必须
                appID: "1256187897", // 请传入点播账号的appID 必须
                autoplay: false //是否自动播放
                //其他参数请在开发文档中查看
			});
		},
		previewImage:function(){
			var $gallery = $("#gallery"),
			$galleryImg = $("#galleryImg");
			$galleryImg.attr("src", event.target.getAttribute("src"));
			$gallery.fadeIn(100);
			$gallery.on("click", function () {
				$gallery.fadeOut(100);
			});
			//删除图片 删除图片的代码也贴出来。
			$(".weui-gallery__del").click(function () {
				console.log('删除');
				$("#picsPlace").find("div").eq(index).remove();
			});
		}
    }
});


